#include "log.h"
#include <stdio.h>
#include <stdarg.h>

#include "app_uart.h"

void usart_put_string_to_fifo(uint8_t *str)
{
    do
    {
        app_uart_put(*str++);
    }
    while(*str != '\0');
}

void __log(uint8_t level, const char * func, uint32_t line, const char * restrict format, ...)
{
    if(level>= __LEVEL__)
    {
        char str[128];
        va_list ap;
        
        snprintf(str, sizeof(str), "[%d]%s(%d):",level,func,line);
//        simple_uart_putstring((const uint8_t *)str);
        usart_put_string_to_fifo((uint8_t *)str);
        
        va_start(ap, format);
        (void)vsnprintf(str, sizeof(str), format, ap);
        va_end(ap);

        usart_put_string_to_fifo((uint8_t *)str);
        usart_put_string_to_fifo((uint8_t *)"\r\n");
        
//        simple_uart_putstring((const uint8_t *)str);
//        simple_uart_putstring((const uint8_t *)"\r\n");
    }
}

void log1(const char * restrict format, ...)
{
    if(1)
    {
        char str[64];
        va_list ap;
        
   
        va_start(ap, format);
        (void)vsnprintf(str, sizeof(str), format, ap);
        va_end(ap);
        
//        simple_uart_putstring((const uint8_t *)str);
//        simple_uart_putstring((const uint8_t *)"\r\n");
    }
}

void log_xx(uint8_t level, const char * func, uint32_t line, const char * restrict format, ...)
{
    
}

